package com.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.entity.MessageRule;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 药物提醒规则配置表 Mapper 接口
 * @author ZM
 * @since 2020-11-23
 */
public interface MessageRuleMapper extends BaseMapper<MessageRule> {

    /**
     * 通过药物ID，获取药物规则（----不循环的药物规则）
     * @param medicineId
     * @return
     */
    MessageRule getRuleByMidNoLoop(@Param("medicineId")Integer medicineId);

    /**
     * 通过药物ID，获取药物规则（----循环的药物规则）
     * @param medicineId
     * @return
     */
    MessageRule getRuleByMidYesLoop(@Param("medicineId")Integer medicineId);

    @Select("select * from pd_message_rule where deleted_time is null and message_rule_id=#{messageRuleId} limit 1")
    MessageRule queryByIdEffectiveAndInLoop(@Param("messageRuleId") Integer messageRuleId);

    @Select("select * from pd_message_rule where deleted_time is null and medicine_id=#{medicineId} ")
    List<MessageRule> queryListInEffective(@Param("medicineId") Integer medicineId);
}
